<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="盘点结果明细标识,本实体记录的唯一标识" prop="invchkRsltId">
        <el-input
          v-model="queryParams.invchkRsltId"
          placeholder="请输入盘点结果明细标识,本实体记录的唯一标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务标识,盘点任务标识" prop="taskId">
        <el-input
          v-model="queryParams.taskId"
          placeholder="请输入任务标识,盘点任务标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类别,01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" prop="equipCateg">
        <el-input
          v-model="queryParams.equipCateg"
          placeholder="请输入设备类别,01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备标识,设备唯一标识" prop="equipId">
        <el-input
          v-model="queryParams.equipId"
          placeholder="请输入设备标识,设备唯一标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="条形码,本实体记录的唯一标识" prop="barCode">
        <el-input
          v-model="queryParams.barCode"
          placeholder="请输入条形码,本实体记录的唯一标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库房标识,与库房建立关联" prop="whId">
        <el-input
          v-model="queryParams.whId"
          placeholder="请输入库房标识,与库房建立关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库区标识，用来与库区进行关联" prop="whAreaId">
        <el-input
          v-model="queryParams.whAreaId"
          placeholder="请输入库区标识，用来与库区进行关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存放区标识,与存放区建立关联" prop="storeAreaId">
        <el-input
          v-model="queryParams.storeAreaId"
          placeholder="请输入存放区标识,与存放区建立关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="周转柜资产编号" prop="cabinetBarCode">
        <el-input
          v-model="queryParams.cabinetBarCode"
          placeholder="请输入周转柜资产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="柜单元标识,与储位建立关联" prop="unitId">
        <el-input
          v-model="queryParams.unitId"
          placeholder="请输入柜单元标识,与储位建立关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="储位标识,与储位建立关联" prop="storeLocId">
        <el-input
          v-model="queryParams.storeLocId"
          placeholder="请输入储位标识,与储位建立关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="盘点人,进行盘点的人姓名" prop="inventoryChecker">
        <el-input
          v-model="queryParams.inventoryChecker"
          placeholder="请输入盘点人,进行盘点的人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="盘点日期,进行盘点的日期" prop="inventoryChkDate">
        <el-date-picker clearable
          v-model="queryParams.inventoryChkDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择盘点日期,进行盘点的日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="盘点结果。01：盘亏、02：盘盈、03：盘平" prop="rsltCode">
        <el-input
          v-model="queryParams.rsltCode"
          placeholder="请输入盘点结果。01：盘亏、02：盘盈、03：盘平"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产档案是否存在。0：否、1：是" prop="docExistFlag">
        <el-input
          v-model="queryParams.docExistFlag"
          placeholder="请输入资产档案是否存在。0：否、1：是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理标识,预警是否被处理。01：未处理、02：已处理" prop="handleFlag">
        <el-input
          v-model="queryParams.handleFlag"
          placeholder="请输入处理标识,预警是否被处理。01：未处理、02：已处理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理人,盘赢盘亏的处理人" prop="handlerNo">
        <el-input
          v-model="queryParams.handlerNo"
          placeholder="请输入处理人,盘赢盘亏的处理人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理方式,盘赢盘亏的处理方式。01：盘赢资产入库、02：盘亏设备登记" prop="handleMode">
        <el-input
          v-model="queryParams.handleMode"
          placeholder="请输入处理方式,盘赢盘亏的处理方式。01：盘赢资产入库、02：盘亏设备登记"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理日期,盘赢盘亏的处理时间" prop="handleDate">
        <el-date-picker clearable
          v-model="queryParams.handleDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择处理日期,盘赢盘亏的处理时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作标识" prop="operId">
        <el-input
          v-model="queryParams.operId"
          placeholder="请输入操作标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['storage:mdInvChkRlst:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['storage:mdInvChkRlst:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['storage:mdInvChkRlst:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['storage:mdInvChkRlst:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mdInvChkRlstList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="盘点结果明细标识,本实体记录的唯一标识" align="center" prop="invchkRsltId" />
      <el-table-column label="任务标识,盘点任务标识" align="center" prop="taskId" />
      <el-table-column label="设备类别,01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" align="center" prop="equipCateg" />
      <el-table-column label="设备标识,设备唯一标识" align="center" prop="equipId" />
      <el-table-column label="条形码,本实体记录的唯一标识" align="center" prop="barCode" />
      <el-table-column label="库房标识,与库房建立关联" align="center" prop="whId" />
      <el-table-column label="库区标识，用来与库区进行关联" align="center" prop="whAreaId" />
      <el-table-column label="存放区标识,与存放区建立关联" align="center" prop="storeAreaId" />
      <el-table-column label="周转柜资产编号" align="center" prop="cabinetBarCode" />
      <el-table-column label="柜单元标识,与储位建立关联" align="center" prop="unitId" />
      <el-table-column label="储位标识,与储位建立关联" align="center" prop="storeLocId" />
      <el-table-column label="盘点人,进行盘点的人姓名" align="center" prop="inventoryChecker" />
      <el-table-column label="盘点日期,进行盘点的日期" align="center" prop="inventoryChkDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inventoryChkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="盘点结果。01：盘亏、02：盘盈、03：盘平" align="center" prop="rsltCode" />
      <el-table-column label="资产档案是否存在。0：否、1：是" align="center" prop="docExistFlag" />
      <el-table-column label="处理标识,预警是否被处理。01：未处理、02：已处理" align="center" prop="handleFlag" />
      <el-table-column label="处理人,盘赢盘亏的处理人" align="center" prop="handlerNo" />
      <el-table-column label="处理方式,盘赢盘亏的处理方式。01：盘赢资产入库、02：盘亏设备登记" align="center" prop="handleMode" />
      <el-table-column label="处理日期,盘赢盘亏的处理时间" align="center" prop="handleDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.handleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作标识" align="center" prop="operId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['storage:mdInvChkRlst:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['storage:mdInvChkRlst:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改盘点结果明细信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="盘点结果明细标识,本实体记录的唯一标识" prop="invchkRsltId">
          <el-input v-model="form.invchkRsltId" placeholder="请输入盘点结果明细标识,本实体记录的唯一标识" />
        </el-form-item>
        <el-form-item label="任务标识,盘点任务标识" prop="taskId">
          <el-input v-model="form.taskId" placeholder="请输入任务标识,盘点任务标识" />
        </el-form-item>
        <el-form-item label="设备类别,01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" prop="equipCateg">
          <el-input v-model="form.equipCateg" placeholder="请输入设备类别,01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" />
        </el-form-item>
        <el-form-item label="设备标识,设备唯一标识" prop="equipId">
          <el-input v-model="form.equipId" placeholder="请输入设备标识,设备唯一标识" />
        </el-form-item>
        <el-form-item label="条形码,本实体记录的唯一标识" prop="barCode">
          <el-input v-model="form.barCode" placeholder="请输入条形码,本实体记录的唯一标识" />
        </el-form-item>
        <el-form-item label="库房标识,与库房建立关联" prop="whId">
          <el-input v-model="form.whId" placeholder="请输入库房标识,与库房建立关联" />
        </el-form-item>
        <el-form-item label="库区标识，用来与库区进行关联" prop="whAreaId">
          <el-input v-model="form.whAreaId" placeholder="请输入库区标识，用来与库区进行关联" />
        </el-form-item>
        <el-form-item label="存放区标识,与存放区建立关联" prop="storeAreaId">
          <el-input v-model="form.storeAreaId" placeholder="请输入存放区标识,与存放区建立关联" />
        </el-form-item>
        <el-form-item label="周转柜资产编号" prop="cabinetBarCode">
          <el-input v-model="form.cabinetBarCode" placeholder="请输入周转柜资产编号" />
        </el-form-item>
        <el-form-item label="柜单元标识,与储位建立关联" prop="unitId">
          <el-input v-model="form.unitId" placeholder="请输入柜单元标识,与储位建立关联" />
        </el-form-item>
        <el-form-item label="储位标识,与储位建立关联" prop="storeLocId">
          <el-input v-model="form.storeLocId" placeholder="请输入储位标识,与储位建立关联" />
        </el-form-item>
        <el-form-item label="盘点人,进行盘点的人姓名" prop="inventoryChecker">
          <el-input v-model="form.inventoryChecker" placeholder="请输入盘点人,进行盘点的人姓名" />
        </el-form-item>
        <el-form-item label="盘点日期,进行盘点的日期" prop="inventoryChkDate">
          <el-date-picker clearable
            v-model="form.inventoryChkDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择盘点日期,进行盘点的日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="盘点结果。01：盘亏、02：盘盈、03：盘平" prop="rsltCode">
          <el-input v-model="form.rsltCode" placeholder="请输入盘点结果。01：盘亏、02：盘盈、03：盘平" />
        </el-form-item>
        <el-form-item label="资产档案是否存在。0：否、1：是" prop="docExistFlag">
          <el-input v-model="form.docExistFlag" placeholder="请输入资产档案是否存在。0：否、1：是" />
        </el-form-item>
        <el-form-item label="处理标识,预警是否被处理。01：未处理、02：已处理" prop="handleFlag">
          <el-input v-model="form.handleFlag" placeholder="请输入处理标识,预警是否被处理。01：未处理、02：已处理" />
        </el-form-item>
        <el-form-item label="处理人,盘赢盘亏的处理人" prop="handlerNo">
          <el-input v-model="form.handlerNo" placeholder="请输入处理人,盘赢盘亏的处理人" />
        </el-form-item>
        <el-form-item label="处理方式,盘赢盘亏的处理方式。01：盘赢资产入库、02：盘亏设备登记" prop="handleMode">
          <el-input v-model="form.handleMode" placeholder="请输入处理方式,盘赢盘亏的处理方式。01：盘赢资产入库、02：盘亏设备登记" />
        </el-form-item>
        <el-form-item label="处理日期,盘赢盘亏的处理时间" prop="handleDate">
          <el-date-picker clearable
            v-model="form.handleDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理日期,盘赢盘亏的处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="操作标识" prop="operId">
          <el-input v-model="form.operId" placeholder="请输入操作标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMdInvChkRlst, getMdInvChkRlst, delMdInvChkRlst, addMdInvChkRlst, updateMdInvChkRlst } from "@/api/storage/mdInvChkRlst";

export default {
  name: "MdInvChkRlst",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 盘点结果明细信息表格数据
      mdInvChkRlstList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        invchkRsltId: null,
        taskId: null,
        equipCateg: null,
        equipId: null,
        barCode: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        cabinetBarCode: null,
        unitId: null,
        storeLocId: null,
        inventoryChecker: null,
        inventoryChkDate: null,
        rsltCode: null,
        docExistFlag: null,
        handleFlag: null,
        handlerNo: null,
        handleMode: null,
        handleDate: null,
        remark: null,
        operId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        invchkRsltId: [
          { required: true, message: "盘点结果明细标识,本实体记录的唯一标识不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询盘点结果明细信息列表 */
    getList() {
      this.loading = true;
      listMdInvChkRlst(this.queryParams).then(response => {
        this.mdInvChkRlstList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        invchkRsltId: null,
        taskId: null,
        equipCateg: null,
        equipId: null,
        barCode: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        cabinetBarCode: null,
        unitId: null,
        storeLocId: null,
        inventoryChecker: null,
        inventoryChkDate: null,
        rsltCode: null,
        docExistFlag: null,
        handleFlag: null,
        handlerNo: null,
        handleMode: null,
        handleDate: null,
        remark: null,
        operId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.invchkRsltId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加盘点结果明细信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const invchkRsltId = row.invchkRsltId || this.ids
      getMdInvChkRlst(invchkRsltId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改盘点结果明细信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.invchkRsltId != null) {
            updateMdInvChkRlst(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMdInvChkRlst(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const invchkRsltIds = row.invchkRsltId || this.ids;
      this.$modal.confirm('是否确认删除盘点结果明细信息编号为"' + invchkRsltIds + '"的数据项？').then(function() {
        return delMdInvChkRlst(invchkRsltIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('storage/mdInvChkRlst/export', {
        ...this.queryParams
      }, `mdInvChkRlst_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
